<template>
  <SmtChart :change="change" :legendList='legendList' :title='title' :seriesData='seriesData' :height="height" :xAxisData="xAxisData"/>
</template>

<script>
import SmtChart from '@views/dashboard/components/SmtChart'
export default {
  name: 'DIPYR',
  props:{
    height:{
      type:String,
      default:'300px'
    },
    activePart:{
      type:String,
      default:''
    },
  },
  components:{
    SmtChart
  },
  data(){
    return {
      title:'SMT_TOP issue',
      legendList:[],
      seriesData:[],
      xAxisData:[],
      change:true
    }
  },
  computed: {
    begindate () {
      return this.$store.state.app.begindate;　　//需要监听的数据
    },
    enddate () {
      return this.$store.state.app.enddate;　　//需要监听的数据
    },
    kjtext () {
      return this.$store.state.app.kjtext;　　//需要监听的数据
    },
    reSearch(){
      return this.$store.state.app.reSearch;　　//需要监听的数据
    }
  },
  watch:{
    activePart:{
      handler(){
        this.getChartData()
      }
    },
    begindate:{
      handler(newVal,oldVal){
        console.log('begindate',newVal)
        this.getChartData()
      }
    },
    enddate:{
      handler(newVal,oldVal){
        console.log('enddate',newVal)
      }
    },
    kjtext:{
      handler(newVal,oldVal){
        console.log('kjtext',newVal)
        this.getChartData()
      }
    },
    reSearch:{
      handler(newVal,oldVal){
        console.log('reSearch',newVal)
        this.getChartData()
      }
    }
  },
  methods:{
    getChartData(){
      this.$http.get('/inspect/reportapi/getBarData',{
        params:{
          line:this.activePart,
          type:'TOP',
          begindate:this.begindate,
          enddate:this.enddate,
          kjtext:this.kjtext,
          linecode:this.$store.state.app.linecode,
          procode:this.$store.state.app.procode,
        }
      }).then(res=>{
        if (res.success){
          let newVal = res.result
          let lengend = []
          let series = []
          this.title = newVal.name
          lengend.push(newVal.barname)
          lengend.push(newVal.line1name)
          lengend.push(newVal.line2name)
          this.legendList = lengend
          series.push({
            name: newVal.barname,
            type: 'bar',
            data: newVal.bar,
            barMaxWidth:30,
          })
          series.push({
            name: newVal.line1name,
            type: 'line',
            data: newVal.line1,
            yAxisIndex:1
          })
          series.push({
            name: newVal.line2name,
            type: 'line',
            data: newVal.line2,
            yAxisIndex:1
          })
          this.seriesData = series
          this.xAxisData = newVal.xname
          this.change = !this.change
        }else{
          this.$message.error(res.message)
        }
      });
    }
  },
  mounted() {
    this.getChartData()
  }
}
</script>

<style scoped>

</style>